<template>
	<view class="pagesContent">
		<view class="pagesContentView">
			<view class="listView" v-if="list.length != 0">
				<!-- 图片 视频 -->
				<uni-row v-if="scanType=='PICTURE' || scanType== 'VIDEO'">
					<uni-col :span="6" class="itemView" v-for="(item,index) in list " :key="index">
						<view class="item images">
							<image class="price" @click="showItem(item,index)" v-if="scanType=='PICTURE' "
								:src="item.content.filePath" mode="aspectFit"> </image>

							<image class="play" @click="showItem(item,index)" v-if="scanType=='VIDEO' "
								src="../../static/images/mp4Icon.png" mode="aspectFit"></image>
						</view>
					</uni-col>

				</uni-row>
				<!-- 图片 视频 -->
				<view class="filesItem" v-if="scanType=='AUDIO' || scanType== 'FILE'">
					<view class="item files" @click="showItem(item, index)" v-for="(item,index) in list " :key="index">
						<view class="left">
							<image class="icon" v-if="scanType == 'AUDIO'" src="../../static/images/mp3Icon.png"
								mode=""> </image>
							<image class="icon" v-if="scanType == 'FILE'" src="../../static/images/hyisFileIcon.png"
								mode=""></image>
						</view>
						<view class="content"> {{ item.content.fileName | sliceFileName }}
						</view>
					</view>
				</view>
			</view>

			<view class="no_data" v-if="list.length == 0 ">
				<image class="icon" src="../../static/images/noDataIcon.png" mode=""></image>
				<view class="hint">暂无历史记录 </view>
			</view>
			<view class="clear" style="height: 40rpx;"> </view>
			<adView></adView>
			<view class="clear" style="height: 20rpx;"> </view>

		</view>

	</view>
	</view>
</template>

<script>
	import {
		mapGetters,
		mapMutations,
		mapActions
	} from 'vuex'
	import {
		getNowFormatDate_ymd,
		sortDateArray
	} from "../../util/util.js"
	export default {
		data() {
			return {
				scanType: "PICTURE",
				pages: 1,
				limit: 20,
				list: [],
				showBox: true,
			}
		},
		onShow() {
			let this_ = this;
			if (!this.hasLogin) {
				this.goReLaunch("/pages/user/login")
			} else {

				this.scanType = uni.getStorageSync("scanType"); //搜索文件类型对象		
				if (this.scanType == 'PICTURE' || this.scanType == 'ALL_PICTURE' || this.scanType ==
					'VIDEO' || this.scanType == 'ALL_VIDEO') {
					this.showBox = true
				}
				if (this.scanType == 'AUDIO' || this.scanType == 'FILE' || this.scanType == 'ALL_AUDIO' ||
					this.scanType == 'ALL_FILE') {
					this.showBox = false
				}

				let pageTitle = null

				switch (this.scanType) {
					case "PICTURE":
						pageTitle = "图片"
						break;
					case "VIDEO":
						pageTitle = "视频"
						break;
					case "AUDIO":
						pageTitle = "音频"
						break;
					case "FILE":
						pageTitle = "文档"
						break;
				}
				uni.setNavigationBarTitle({
					title: pageTitle
				})


				this.$nextTick(() => {
					this.list = []
					this.pages = 1
					this.getDataType(this.scanType)
				})
			}
		},
		computed: {
			...mapGetters(["hasLogin"])
		},
		onPullDownRefresh() {
			console.log('refresh');
			this.pages = 1
			this.hisList = []
			this.list = []
			this.getDataType(this.scanType)
		},
		methods: {
			getDataType(type) {
				uni.showLoading({
					title: '加载中...'
				});
				let params = {
					type: type,
					page: this.pages,
					limit: this.limit
				}
				console.log(params)
				this.$http.post("/api/store/list", params).then(res => {
					console.log(res)
					uni.hideLoading()
					uni.stopPullDownRefresh();
					if (res.code == 0) {
						if (res.data.list.length != 0) {
							this.list = [...this.list, ...res.data.list]

						} else {
							this.text("没有更多了")
						}
					} else {
						this.text(res.data.message)
					}
				})
			},
			showItem(m) {
				uni.setStorageSync("previewFrom", "hisList")
				uni.setStorageSync("selectItem_id", m.id)
				uni.setStorageSync("selectItem", JSON.stringify(m.content))
				uni.setStorageSync("scanType", m.type)
				if (this.appVipSwitch) { //需要会员
					if (this.userInfo.vip_info.is_vip) { //是会员
						this.goPage("/pages/preview/index")
					} else { //不是会员
						this.goPage("/pages/user/member")
					}
				} else {
					this.goPage("/pages/preview/index")
				}
			},
		}
	}
</script>
<style>
	page {
		background: #ffffff;
	}
</style>

<style lang="scss" scoped>
	.pagesContent {
		position: fixed;
		top: 40rpx;
		left: 0;
		right: 0;
		bottom: 0;
		border-radius: 48rpx 48rpx 0 0;
		background: #FFFFFF;
		box-shadow: 0px 0px 32rpx 0px rgba(51, 114, 251, 0.27);
		border-radius: 48rpx 48rpx 0px 0px;
		overflow: hidden;

		.pagesContentView {
			position: relative;
			border-radius: 48rpx 48rpx 0 0;
			width: 100%;
			height: 100%;
			padding-top: 40rpx;


			.listView {
				padding: 0 32rpx;

				.itemView {
					margin-bottom: 8rpx;

					.images {
						width: 170rpx;
						height: 170rpx;
						margin: 0 auto;
						background: #EEF3FF;
						border: 8rpx;
						overflow: hidden;

						.price {
							width: 170rpx;
							height: 170rpx;
							display: block;
						}

						.play {
							width: 170rpx;
							height: 170rpx;
							display: block;
						}

					}

				}

				.filesItem {
					padding: 0 32rpx;

					.files {
						height: 100rpx;
						margin-bottom: 20rpx;

						.left {
							.icon {
								width: 100rpx;
								height: 100rpx;
								float: left;
							}
						}

						.content {
							float: left;
							margin-left: 20rpx;
							height: 100rpx;
							line-height: 100rpx;
						}
					}
				}

			}


			.no_data {
				padding-top: 153rpx;

				.icon {
					width: 314rpx;
					height: 264rpx;
					display: block;
					margin: 0 auto 25rpx;
				}

				.hint {
					text-align: center;
					height: 44rpx;
					font-size: 28rpx;
					font-family: AlibabaPuHuiTi_20;
					font-weight: normal;
					color: #939599;
					line-height: 44rpx;
					margin-bottom: 50rpx;
				}
			}
		}


	}
</style>